/**
 *
 * @author: Marek Zakowicz <mazak (at) debian (dot) linux.org.pl>
 *
 * Copyright (c) 2005, 2006, 2007 Marek Zakowicz. All rights reserved.
 *
 * Licence: This code may be used, (re)distribute and/or modify under the terms one of the following two kinds of licence:
 *          1) as free software under GPL 3 (General Public Licence ver. 3 as published by the Free Software Foundation)
 *          2) as software under the terms individual licence from Marek Zakowicz
 *
 *          This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *          without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

package jsp2php;

// Utility class - its methods calculate result type of value operation
public class TypeCalculator {

   private static JavaType _int     = JavaType.integer();
   private static JavaType _double  = JavaType._double();
   private static JavaType _boolean = JavaType.bool();
   private static JavaType _string  = JavaType.string();

   private TypeCalculator() {
   }

   // Calculate result type of addition result
   static JavaType add_type(JavaType left, JavaType right) throws TranslatorException {
      if(left == _string || right == _string) {
         return _string;
      }
      if(left == _double || right == _double) {
         return _double;
      }
      if(left == _int && right == _int) {
         return _int;
      }
      throw new TranslatorException("Java "+ left +" and "+ right +" are not additive!");
   }

   // Calculate result type of multiplication, division and modulo.
   static JavaType mul_type(JavaType left, JavaType right) throws TranslatorException {
      if(left == _double || right == _double) {
         return _double;
      }
      if(left == _int && right == _int) {
         return _int;
      }
      throw new TranslatorException("Java "+ left +" and "+ right +" are not multiplicative!");
   }

}
